﻿using System;
using System.Data;
using System.Linq;
using System.Linq.Expressions;

namespace MicroDb.SqlServer
{
    class SqlServerResolveNone : SqlServerResolveBase
    {
        public SqlServerResolveNone(Expression expression, SqlExecute sqlExecute = null) : base(sqlExecute)
        {
            if (expression.NodeType == ExpressionType.Constant)
            {
                base.TableType = (GetValue(expression) as IQueryable).ElementType;
            }
            else
            {
                throw new Exception("无效的 lambed");
            }
        }
        public override string BuildSql(bool isEasy = false)
        {
            return GetTabName();
        }

        public override object GetResult()
        {
            return TryCreateTable(() =>
             {
                 string sql = $"SELECT * FROM {GetTabName()}";
                 return sqlExecute.ExecuteListObject(CommandType.Text, sql, Args, base.TableType);
             });
        }

    }
}